Page({
  t: "",
  e: "",
  audioSrcList: [{
    title: '你干嘛',
    src: 'niganma'
  }, {
    title: '哎哟',
    src: 'ai_yo'
  }, {
    title: '鸡',
    src: 'ji'
  }, {
    title: '姬霓太美',
    src: 'ji_ni_tai_mei'
  }, {
    title: '敲木鱼',
    src: 'qiaoji'
  }, {
    title: '颂钵',
    src: 'songbo'
  }],
  src: '',
  data: {
    auto: !1,
    count: 0,
    audio: !0,
    opengo: !0,
    showAudioList: false, //显示音乐盒内容列表
    audioSrcIndex: 0, //默认选中音频下标
    mode: 'zoom', //坤坤模式。zoom：缩放模式。shock：震动模式。music：坤音盒
  },

  onLoad() {
    wx.setInnerAudioOption({
      obeyMuteSwitch: false
    })
    this.src = this.data.mode == 'zoom' ? this.audioSrcList[0].src : this.audioSrcList[2].src
    this.setData({
      audioSrcIndex: this.data.mode == 'zoom' ? 0 : 2
    })
    this.createAudio()
    this.createAnimate()
  },
  // 创建音频
  createAudio() {
    this.innerAudioContext = wx.createInnerAudioContext()
    this.innerAudioContext.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext.onPlay(function () {})
    this.innerAudioContext.onError(function (t) {
      console.log(t.errMsg)
      console.log(t.errCode);
    })
    this.innerAudioContext2 = wx.createInnerAudioContext()
    this.innerAudioContext2.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext2.onPlay(function () {})
    this.innerAudioContext2.onError(function (t) {
      console.log(t.errMsg)
      console.log(t.errCode);
    })
    this.innerAudioContext3 = wx.createInnerAudioContext()
    this.innerAudioContext3.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext3.onPlay(function () {})
    this.innerAudioContext3.onError(function (t) {
      console.log(t.errMsg)
      console.log(t.errCode);
    })
    this.innerAudioContext4 = wx.createInnerAudioContext()
    this.innerAudioContext4.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext4.onPlay(function () {})
    this.innerAudioContext4.onError(function (t) {
      console.log(t.errMsg)
      console.log(t.errCode);
    })
    this.testInner = wx.createInnerAudioContext()
  },
  // 创建动画
  createAnimate() {
    // 创建横向木棍动画
    this.aniamtion = wx.createAnimation({
      duration: 50,
      transformOrigin: "right top",
      timingFunction: "ease-in-out"
    });
    // 创建文字动画
    for (var o = 0; o < 10; o++) this["agd" + o] = wx.createAnimation({
      duration: 250,
      transformOrigin: "right top",
      timingFunction: "ease-out"
    });
    // 创建木鱼缩放动画
    this.aniamtion2 = wx.createAnimation({
      duration: 50,
      transformOrigin: "right top",
      timingFunction: "ease-in-out"
    });
    // 创建木鱼震动动画
    this.aniamtion3 = wx.createAnimation({
      duration: 50,
      transformOrigin: "right top",
      timingFunction: "ease-in-out"
    });
    // 创建竖向木棍动画
    this.aniamtion4 = wx.createAnimation({
      duration: 50,
      transformOrigin: "right top",
      timingFunction: "ease-in-out"
    });
  },
  // 敲木鱼
  konck() {
    this.testInner.stop()
    this.data.audio && (this.data.count % 4 == 0 ? (this.innerAudioContext4.stop(),
      this.innerAudioContext4.play()) : this.data.count % 3 == 0 ? (this.innerAudioContext3.stop(),
      this.innerAudioContext3.play()) : this.data.count % 2 == 0 ? (this.innerAudioContext2.stop(),
      this.innerAudioContext2.play()) : (this.innerAudioContext.stop(),
      this.innerAudioContext.play()));
    var t = "" + this.data.count,
      e = t.substr("" + t.length - 1);
    // console.log(e);
    var n = ["agd" + e];
    this["agd" + e].top("51%").step().top("35%").opacity(1).step(50).opacity(0).step().step().top("51%")
    if (this.data.mode == 'zoom') {
      // 横向木棍效果
      this.aniamtion.rotate(0).step().rotate(40).step()
      // 坤坤缩放效果
      this.aniamtion2.width('660rpx').height('534.6rpx').step().width('600rpx').height('486rpx').step()
      this.setData({
        animationData: this.aniamtion.export(),
        animationData2: this.aniamtion2.export(),
        [n]: this["agd" + e].export(),
      })
    } else {
      // 竖向木棍效果
      this.aniamtion3.rotate(25).step().rotate(-25).step()
      // 坤坤震动效果
      this.aniamtion4.translate3d(-1, 0, 0).step().translate3d(2, 0, 0).step().translate3d(-4, 0, 0).step().translate3d(4, 0, 0).step().translate3d(-4, 0, 0).step().translate3d(4, 0, 0).step().translate3d(-4, 0, 0).step().translate3d(2, 0, 0).step().translate3d(-1, 0, 0)
      this.setData({
        animationData: this.aniamtion3.export(),
        animationData2: this.aniamtion4.export(),
        [n]: this["agd" + e].export(),
      })
    }
    this.setData({
      count: this.data.count + 1,
      showAudioList: false
    })
  },
  // 显示所有音频信息
  showAudioList() {
    this.setData({
      showAudioList: !this.data.showAudioList,
      audioSrcList: this.audioSrcList,

    })
  },
  // 切换音频
  changeAudioSrc(e) {
    let {
      index
    } = e.currentTarget.dataset
    this.setData({
      // showAudioList: false,
      audioSrcIndex: index
    })
    this.src = this.audioSrcList[index].src
    this.innerAudioContext.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext2.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext3.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.innerAudioContext4.src = `/pages/happyTools/audio/${this.src}.mp3`

    this.testInner.src = `/pages/happyTools/audio/${this.src}.mp3`
    this.testInner.play()
  },
  // 切换模式
  changeMode(e) {
    let {
      mode
    } = e.currentTarget.dataset
    this.setData({
      mode,
    })
  },
  onShareAppMessage() {
    return {
      title: "超好玩的坤坤木鱼",
      path: "/pages/happyTools/pages/kunDe/index",
      imageUrl: '/images/function_icon/kunde.png',
    }
  },
  onShareTimeline() {
    return {
      title: '超好玩的坤坤木鱼',
      imageUrl: '/images/function_icon/kunde.png',
    }
  },
})